﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Project_KhuyenMaiVang.Models;
using Project_KhuyenMaiVang.DataProvider;
using System.Data.SqlClient;
using System.Data;

namespace Project_KhuyenMaiVang.DAO
{
    public class TinhTrangAccountDAO : MyDataProvider
    {
        // Lấy tình trạng account
        // parameter    : mã tình trạng account
        // return       : tên tình trạng account
        public string getAccountState(int idAccountState)
        {
            TinhTrangAccountDTO result = new TinhTrangAccountDTO();
            try
            {
                string strCommand = "SELECT* FROM TinhTrangAccount WHERE MaTinhTrang = " + idAccountState.ToString();
                _Adapter = new SqlDataAdapter(strCommand, _Connection);
                DataSet dataset = new DataSet();
                _Adapter.Fill(dataset);
                DataTable dt = dataset.Tables[0];
                object ob = GetDataFromDataRow(dt, 0);
                result = (TinhTrangAccountDTO)ob;
            }
            catch (Exception ex)
            {
                result = null;
            }

            return result.TinhTrang;
        }

        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            TinhTrangAccountDTO state = new TinhTrangAccountDTO();
            state.MaTinhTrang = Int32.Parse(dt.Rows[i]["MaTinhTrang"].ToString());
            state.TinhTrang = dt.Rows[i]["TinhTrang"].ToString();

            return (object)state;
        }
    }
}